package maxArea;

public class Solution {

    public static void main(String[] args) {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(new Solution().maxArea(height));
    }

    public int maxArea(int[] height) {

        int max = -1;

        int i = 0, j = height.length - 1;

        while (i < j) {
            int h = height[i] > height[j] ? height[j] : height[i];
            int s = (j - i) * h;
            max = max > s ? max : s;
            if(height[i] < height[j])i++;
            else j--;
        }

        return max;
    }
}
